package com.kwedding.service.app;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kwedding.bean.TB_Media;
import com.kwedding.dao.TB_MediaMapper;
import com.kwedding.dto.app.RequestgetMedia;
import com.kwedding.dto.app.ResponseMedia;
import com.kwedding.util.CheckedUtil;
import com.kwedding.util.Constants;
import com.kwedding.util.CopyerObject;
import com.kwedding.util.LoggerParent;
import com.kwedding.util.RequestErrorBackException;

@Service
public class MediaService extends LoggerParent {

	@Autowired
	private TB_MediaMapper tb_MediaMapper;

	/**
	 * 获取视频
	 * 
	 * @param requestgetMedia
	 */
	@Transactional(readOnly = true)
	public ResponseMedia getMeida(RequestgetMedia requestgetMedia) {
		CheckedUtil.isNull(requestgetMedia.getBrandId(), Constants.REQUEST_ERROR_1, "请选择品牌");
		CheckedUtil.isNull(requestgetMedia.getType(), Constants.REQUEST_ERROR_2, "类型不能为空");
		TB_Media tb_Media = tb_MediaMapper.selectMediaInUse(requestgetMedia.getBrandId(), requestgetMedia.getType());
		if (tb_Media == null) {
			throw new RequestErrorBackException(Constants.REQUEST_ERROR_3, "该类型视频不存在或已删除");
		}
		ResponseMedia responseMedia = CopyerObject.copyerObject(tb_Media, ResponseMedia.class);
		return responseMedia;
	}

}
